home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1996-01-17 | 3.8 KB | 134 lines |
- ' ************************************* Commands used:
- ' * * Vec Rot Pos Blitter Clear
- ' * Amcaf Examples * Vec Rot Angles =Qsin
- ' * Vector Rotate Solid + Light V1.1 * Vec Rot Precalc =Mix Colour
- ' * Written by Chris Hodges * =Vec Rot X
- ' * * =Vec Rot Y
- ' ************************************* =Vec Rot Z
- '
- ' Remove mouse pointer.
- Hide
- ' Setup a nice little screen with double buffering
- Screen Open 0,320,256,8,Lowres
- Curs Off : Flash Off : Paper 0 : Pen 1 : Cls
- Double Buffer
- Autoback 0
- ' Read out how many colours are used, and then their values.
- Restore OBJCOLS
- Read NUMCV
- Dim CVAL(NUMCV)
- For A=1 To NUMCV
- Read CVAL(A)
- Next
- ' Read out, how many coords are used.
- Restore COORDS
- Read NUMCO
- ' Dim one field to keep these coords, and a second for the rotated.
- Dim CO(NUMCO,2),RC(NUMCO,2)
- ' Now read all coords in.
- For A=1 To NUMCO
- Read CO(A,0),CO(A,1),CO(A,2)
- Next
- ' Then, get the number of shapes the object consists of.
- Restore SHAPES
- Read NUMLI
- ' Dim a field to hold the four coords.
- Dim LI(NUMLI,4)
- ' Get the datas.
- For A=1 To NUMLI
- Read LI(A,0),LI(A,1),LI(A,2),LI(A,3)
- Read LI(A,4)
- Next
- ' Set the three angles. Remember that these are non standard angles,
- ' one full rotation is at 1024, not 360!
- AX=0 : AY=512 : AZ=128
- Repeat
- ' Start clearing bitplane 0.
- Extension_8_121C 0,0
- ' While the blitter is working, use the time to calculate the rotations.
- ' Move and set the angles.
- Add AX,5
- Add AY,8
- Add AZ,11
- Extension_8_1138 AX,AY,AZ
- ' Calculate the distances by using a sine-function and the three angles.
- POSX= Extension_8_1106(AX,300)
- POSY= Extension_8_1106(AY,300)
- POSZ= Extension_8_1106(AZ,500)+1500
- ' Set the camera positions.
- Extension_8_1122 POSX,POSY,POSZ
- ' Now it's time to compute the matrix.
- Extension_8_1152
- ' Clear bitplane 1
- Extension_8_121C 0,1
- ' So let's rotate all coordinates of the field CO()
- For A=1 To NUMCO
- ' Note: You only have to use the vec rot function with parameters once.
- RC(A,0)= Extension_8_1168(CO(A,0),CO(A,1),CO(A,2))+160
- RC(A,1)= Extension_8_1184 +128
- RC(A,2)= Extension_8_11C4 -POSZ
- Next
- ' Clear bitplane 2
- Extension_8_121C 0,2
- ' It's time to finally get the polygons to the screen!
- For A=1 To NUMLI
- ' Get the four coordinates pairs.
- C1=LI(A,0) : C2=LI(A,1) : C3=LI(A,2) : C4=LI(A,3)
- CO=LI(A,4)
- ' Get the rotated coordinates
- X1=RC(C1,0) : Y1=RC(C1,1)
- X2=RC(C2,0) : Y2=RC(C2,1)
- X3=RC(C3,0) : Y3=RC(C3,1)
- X4=RC(C4,0) : Y4=RC(C4,1)
- ' Use some maths, to see if the plane faces into the camera or into
- ' the back. This formula works ONLY, if the polygon is drawn
- ' clockwise!
- DI=(X3-X1)*(Y2-Y1)-(X2-X1)*(Y3-Y1)
- If DI<0
- ' Calculate the new colour value. This time, only simple maths
- ' is used, and it will not be 100% correct, but it works :)
- Z=-RC(C1,2)-RC(C2,2)-RC(C3,2)-RC(C4,2)
- ' Add or sub from this colour.
- NC= Extension_8_0EE8(CVAL(CO),$111*Max(Min((Z/16)-13,15),-15),0 To $FFF)
- Colour CO,NC
- ' Draw the polygons in colour CO
- Ink CO
- Polygon X1,Y1 To X2,Y2 To X3,Y3 To X4,Y4
- End If
- Next
- ' Swap the screens to bring the object to view.
- Screen Swap
- Wait Vbl
- Until Inkey$=Chr$(27) or Mouse Key<>0
- Screen Close 0
- End
- OBJCOLS:
- Data 6
- Data $F44,$4F4,$FF4,$44F,$F4F,$4FF
- ' 1_____2
- ' 5/____/|
- ' | | |6|
- ' |4|__|_|3
- ' |/___|/
- ' 8 7
- COORDS:
- Data 8
- ' CUBE
- Data -100,-100,-100
- Data 100,-100,-100
- Data 100,-100,100
- Data -100,-100,100
- Data -100,100,-100
- Data 100,100,-100
- Data 100,100,100
- Data -100,100,100
-
- SHAPES:
- Data 6
- ' All lines are drawn clockwise.
- Data 1,2,6,5,1
- Data 4,3,2,1,2
- Data 2,3,7,6,3
- Data 3,4,8,7,4
- Data 4,1,5,8,5
- Data 6,7,8,5,6